<template>
  <div class="queue-info-bg">
    <div class="queue-info-center">
      <el-card class="queue-info-card">
        <div class="queue-info-title">
          <el-icon class="queue-icon"><UserFilled /></el-icon>
          <span>排队信息</span>
        </div>
        <div class="queue-info-content">
          <div class="queue-info-item">
            <el-icon class="item-icon"><CreditCard /></el-icon>
            <span class="item-label">排队编号</span>
            <span class="item-value">{{ info?.queue_num || '-' }}</span>
          </div>
          <div class="queue-info-item">
            <el-icon class="item-icon"><Tickets /></el-icon>
            <span class="item-label">当前状态</span>
            <el-tag :type="stateTagType" class="item-value">{{ stateText }}</el-tag>
          </div>
          <div class="queue-info-item">
            <el-icon class="item-icon"><User /></el-icon>
            <span class="item-label">前方等待车辆数</span>
            <span class="item-value">{{ info?.car_number_before_position ?? '-' }}</span>
          </div>
        </div>
        <div class="queue-info-actions">
          <el-button type="primary" @click="fetchData" :loading="loading">刷新</el-button>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'
import { UserFilled, CreditCard, Tickets, User } from '@element-plus/icons-vue'

const info = ref(null)
const loading = ref(false)

const fetchData = async () => {
  loading.value = true
  try {
    const car_id = localStorage.getItem('car_id')
    const res = await axios.get(process.env.VUE_APP_BACKEND_URL + '/user/checkWaitQueue?car_id=' + car_id)
    if (res.data.code === 0) {
      info.value = res.data.data
    } else {
      info.value = null
      ElMessage.error(res.data.msg || '获取排队信息失败')
    }
  } catch (e) {
    info.value = null
    ElMessage.error('网络错误')
  } finally {
    loading.value = false
  }
}

const stateText = computed(() => {
  if (!info.value) return '-'
  switch (info.value.car_state) {
    case 'waiting': return '排队中'
    case 'charging': return '充电中'
    case 'finished': return '已完成'
    default: return info.value.car_state
  }
})
const stateTagType = computed(() => {
  if (!info.value) return ''
  switch (info.value.car_state) {
    case 'waiting': return 'info'
    case 'charging': return 'success'
    case 'finished': return 'warning'
    default: return ''
  }
})

onMounted(fetchData)
</script>

<style scoped>
.queue-info-bg {
  min-height: 100vh;
  background: linear-gradient(135deg, #2b3391 0%, #3d47b3 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.queue-info-center {
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
}
.queue-info-card {
  width: 100%;
  max-width: 420px;
  border-radius: 20px;
  box-shadow: 0 8px 32px rgba(43, 51, 145, 0.18);
  padding: 40px 32px 24px 32px;
  background: #fff;
  animation: fadeIn 0.6s cubic-bezier(0.4,0,0.2,1);
}
.queue-info-title {
  display: flex;
  align-items: center;
  font-size: 28px;
  font-weight: bold;
  color: #2b3391;
  margin-bottom: 36px;
  gap: 12px;
  justify-content: center;
}
.queue-icon {
  font-size: 32px;
  color: #2b3391;
}
.queue-info-content {
  display: flex;
  flex-direction: column;
  gap: 32px;
  margin-bottom: 32px;
}
.queue-info-item {
  display: flex;
  align-items: center;
  font-size: 22px;
  gap: 12px;
  justify-content: flex-start;
}
.item-icon {
  font-size: 28px;
  color: #3d47b3;
}
.item-label {
  color: #666;
  min-width: 120px;
  font-size: 20px;
}
.item-value {
  color: #2b3391;
  font-weight: bold;
  font-size: 22px;
}
:deep(.el-tag) {
  font-size: 20px;
  padding: 0 16px;
}
.queue-info-actions {
  display: flex;
  justify-content: center;
  margin-top: 12px;
}
@media (max-width: 600px) {
  .queue-info-card {
    padding: 20px 6px 12px 6px;
    max-width: 98vw;
  }
  .queue-info-title {
    font-size: 22px;
    margin-bottom: 20px;
  }
  .queue-info-content {
    gap: 18px;
    margin-bottom: 18px;
  }
  .queue-info-item {
    font-size: 16px;
    gap: 8px;
  }
  .item-label {
    font-size: 15px;
    min-width: 80px;
  }
  .item-value {
    font-size: 16px;
  }
  :deep(.el-tag) {
    font-size: 15px;
    padding: 0 8px;
  }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}
</style> 